package cn.edu.lcu.cs.javaprogramming.thread;

/**
 * @author ling
 * @date 2022/5/29 11:09
 */
public class LambdaThreadClient {
    public static void main(String[] args) throws InterruptedException {
        // 使用Lambda表达式创建一个线程
        Thread thread = new Thread(() -> {
            int localCount = 0;
            while (true) {
                System.out.println(Thread.currentThread().getName() + " 被调用了 " + ++localCount + "次");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();

        int count = 0;
        while (true) {
            System.err.println(Thread.currentThread().getName() + " 被调用了 " + ++count + "次");
            // 线程休眠1000毫秒，纯粹是为了让控制台输出速度慢一点，不然快速变化的输出会把人闪晕。
            Thread.sleep(1000);
        }

    }
}
